from selenium.webdriver.common.by import By

from base.base_page import BasePage


class Cxsq(BasePage):

    cxsq=(By.XPATH,'//span[text()="查询申请"]') #功能点击--可以参数化--多个功能进行点击
    selah=(By.XPATH,'//span[@title="选择对象"]') #//span[@title="选择对象"]   //*[@id="tr_1"]/td/table/tbody/tr[1]/td[3]/span/img
    buttonframe=(By.NAME,'iframe')  #By.XPATH,'//*[@id="ext-gen111"]'
    formframe=(By.XPATH,'//*[@id="win_detail"]')
    button_cx=(By.XPATH,'//*[@id="btnCx"]/tbody/tr/td[2]/em/input')
    fristdata=(By.XPATH,'//*[@id="ajxx"]/div[2]/table/tbody/tr[2]') #第一条数据,可能需要参数话--案件
    njyhXzdwdm=(By.ID,'YH_YH000007')  #可以参数化
    bc=(By.XPATH,'//input[@value="保存"]')

    dialog=(By.XPATH, '//*[@id="ext-comp-1001"]/tbody/tr[2]/td[2]') #提示框的确认按钮
    scws = (By.XPATH, '//input[@value="生成文书"]')
    send = (By.XPATH, '//input[@value="发送"]')
    def intocxsq(self):
        # self.driver.implicitly_wait(2)
        self.click(Cxsq.cxsq)

    def cxdximport(self):
        self.driver.implicitly_wait(2)
        self.goto_iframe(Cxsq.buttonframe)
        self.goto_iframe(Cxsq.formframe)
        self.click(Cxsq.selah)
        current_window = self.get_current_window()
        for handl in self.get_allwindows():
            if handl != current_window:
                self.goto_otherwindow(handl)
                self.driver.implicitly_wait(2)
                self.click(Cxsq.button_cx)
                self.double_click(Cxsq.fristdata)
        #返回表格页面
        self.goto_otherwindow(current_window)
        self.goto_iframe(Cxsq.buttonframe)
        self.goto_iframe(Cxsq.formframe)
        self.click(Cxsq.njyhXzdwdm)
        # self.goto_otherwindow(current_window)  #这个和下面的实现效果一杨
        self.goto_default_content()        # driver.switch_to.default_content()
        self.goto_iframe(Cxsq.buttonframe)
        self.click(Cxsq.bc)  #点击保存

    ddlog=(By.XPATH,'//*[@id="ext-gen28"]')
    def ConfirmDialog(self):
        self.goto_iframe(Cxsq.formframe)  #返回主页面(提示信息的frame)
        self.Dialogs=self.locater_element(Cxsq.ddlog).text
        print(self.Dialogs)
        self.click(Cxsq.dialog)


    def CreatWs(self):
        if self.Dialogs=='保存成功':
            self.goto_default_content()
            self.goto_iframe(Cxsq.buttonframe)
            self.click(Cxsq.scws)
        else:
            pass
    def dosend(self):
        if self.Dialogs =="文书生成成功。":
            self.goto_default_content()
            self.goto_iframe(Cxsq.buttonframe)
            self.click(Cxsq.send)






